import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import layout from "@/layouts/baseLayout.vue";

NProgress.configure({showSpinner: false});

const routes = [
  {
    path: '/',
    name: 'home',
    component: layout,
    redirect:'/index',
    children: [
      {
        path: '/index',
        name: 'index',
        component: () => import( "@/views/home/index.vue" )
      },
      {
        path: '/statistics',
        name: 'statistics',
        component: () => import( "@/views/statistics/index.vue" )
      },
    ]
    
  }, {
    path: '/loading',
    name: 'loading',
    component: () => import( "@/views/Loading.vue" )
  }, {
    path: '/404',
    name: '404',
    component: () => import( "@/views/404.vue" )
  }
];

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes
});

router.beforeEach( (to, from, next) => {
  NProgress.start();
  if(!to.name){
    router.push('/404');
  };
  next();
});

router.afterEach(() => {
  NProgress.done(); // finish progress bar
});

export default router;
